package com.lzx.demo.work6;

/**
 * @author 程序员星星
 * @date 2023/5/4
 * @Description
 */
public class Account {
    private String username;//用户名
    private String passcode;//密码
    private double balance;//余额

    public Account(String username, String passcode, double balance) {
        this.username = username;
        this.passcode = passcode;
        this.balance = balance;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPasscode() {
        return passcode;
    }

    public void setPasscode(String passcode) {
        this.passcode = passcode;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    //存钱
    public void saveMoney(double money) {
        balance += money;
        System.out.printf("%s存了%.2f元，账户余额为%.2f元。\n", username, money, balance);
    }

    //取钱
    public void drawMoney(double money) {
        if (balance - money < 0) {
            System.out.println("账户余额不足，无法取钱");
        } else {
            balance -= money;
            System.out.printf("%s取了%.2f元，账户余额为%.2f元。\n", username, money, balance);
        }
    }

    //显示账户信息
    public void show() {
        System.out.printf("username:%s\n", username);
        System.out.printf("balance:%.2f\n", balance);
    }
}
